<template>
	<view>
		<view class="header">
			<text class="title">智能闹钟</text>
		</view>
		
		<view class="btn-container">
			<view class="btn primary" @click="navigateToAlarmList">
				<text class="btn-text">闹钟列表</text>
			</view>
			
			<view class="btn primary" @click="navigateToAddAlarm">
				<text class="btn-text">添加闹钟</text>
			</view>
			
			<view class="btn" @click="doUtsAdd">
				<text class="btn-text">快速添加闹铃</text>
			</view>
			
			<view class="btn" @click="doUtsDelete">
				<text class="btn-text">删除闹铃</text>
			</view>
		</view>
		
		<view class="info-section">
			<text class="info-title">功能说明</text>
			<view class="info-item">
				<text class="info-text">1. 闹钟列表：查看和管理所有闹钟</text>
			</view>
			<view class="info-item">
				<text class="info-text">2. 添加闹钟：创建新闹钟，支持自定义周期</text>
			</view>
			<view class="info-item">
				<text class="info-text">3. 快速添加：快速创建一个默认闹钟</text>
			</view>
			<view class="info-item">
				<text class="info-text">4. 删除闹铃：删除所有闹钟</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		alarmAdd,
		alarmDelete
	} from "@/uni_modules/laoqianjunzi-alarm"; 
	export default {
		data() {
			return {
			
			};
		},

		onLoad() {

		},
		methods: {
			// 跳转到闹钟列表页面
			navigateToAlarmList() {
				uni.navigateTo({
					url: '/pages/alarm-list/alarm-list'
				});
			},
			
			// 跳转到添加闹钟页面
			navigateToAddAlarm() {
				uni.navigateTo({
					url: '/pages/alarm-add/alarm-add'
				});
			},

			// 快速添加闹钟
			doUtsAdd() {
				let params = {
					name : 'dida', //闹铃名称
					weekday : '123456', //重复星期
					hour : 10, //闹铃时
					minutes : 14, //分钟
					ringtone : 'https://jubaomusics.oss-cn-beijing.aliyuncs.com/%E4%B8%89%E5%8F%AA%E5%B0%8F%E7%8C%AA/%E4%B8%89%E5%8F%AA%E5%B0%8F%E7%8C%AA.mp3', //铃声
				}
				alarmAdd({
					params:params,
					success: (res) => {
						console.log('success', res)
						uni.showToast({
							title: '添加闹铃成功',
							icon: 'success'
						});
					},
					fail: (res) => {
						console.log('fail', res)
						if(res.code === -1 && res.data === "权限") {
							// 提示用户授予权限
							uni.showModal({
								title: '提示',
								content: '需要闹钟权限才能使用此功能，请在系统设置中授予权限',
								confirmText: '去设置',
								success: function (res) {
									if (res.confirm) {
										// 打开应用设置页面
										if(uni.getSystemInfoSync().platform === 'android') {
											plus.runtime.openURL('package:' + plus.runtime.appid);
										}
									}
								}
							});
						}
					},
					complete: () => {
						console.log('complete')
					},
				})
			},
			doUtsDelete() {
				alarmDelete()
			},
			

		},
	};
</script>
<style>
	.header {
		padding: 40rpx 30rpx;
		background-color: #007AFF;
	}
	
	.title {
		font-size: 40rpx;
		font-weight: bold;
		color: #FFFFFF;
	}
	
	.btn-container {
		padding: 30rpx;
	}
	
	.btn {
		margin-bottom: 30rpx;
		padding: 30rpx;
		background-color: #F5F5F5;
		border-radius: 15rpx;
		text-align: center;
	}
	
	.btn.primary {
		background-color: #007AFF;
	}
	
	.btn-text {
		font-size: 32rpx;
		color: #333333;
	}
	
	.btn.primary .btn-text {
		color: #FFFFFF;
	}
	
	.info-section {
		padding: 30rpx;
		background-color: #F9F9F9;
		margin: 20rpx 30rpx;
		border-radius: 15rpx;
	}
	
	.info-title {
		font-size: 32rpx;
		font-weight: bold;
		margin-bottom: 20rpx;
		color: #333333;
	}
	
	.info-item {
		margin-bottom: 15rpx;
	}
	
	.info-text {
		font-size: 28rpx;
		color: #666666;
		line-height: 1.5;
	}
</style>